<%@page import="com.liferay.portal.kernel.servlet.SessionMessages"%>
<%@page import="com.liferay.portal.kernel.servlet.SessionErrors"%>
<%@include file="/html/init.jsp"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<portlet:renderURL var="showPageViewURL">
	<portlet:param name="action" value="showPageView" />
</portlet:renderURL>

<portlet:actionURL var="showPageInsertNewSubjectURL">
	<portlet:param name="action" value="showPageInsertNewSubject" />
</portlet:actionURL>

<portlet:actionURL var="editYearOfSemesterURL">
	<portlet:param name="action" value="increaseYearOfSemester" />
</portlet:actionURL>

<portlet:actionURL var="showListFacultyURL">
	<portlet:param name="action" value="showListFaculty" />
</portlet:actionURL>

<portlet:actionURL var="showSubjectByFacultyURL">
	<portlet:param name="action" value="showSubjectByFaculty" />
</portlet:actionURL>

<portlet:renderURL var="showPageInsertNewSubjectByFacultyURL">
	<portlet:param name="action" value="showPageInsertNewSubjectByFaculty" />
</portlet:renderURL>

<portlet:actionURL var="decreaseSemesterByIdURL">
	<portlet:param name="action" value="decreaseSemesterById" />
</portlet:actionURL>

<portlet:actionURL var="deleteCheckedSubjectByIdURL">
	<portlet:param name="action" value="deleteCheckedSubjectById" />
</portlet:actionURL>

<portlet:actionURL var="deleteCheckedSubjectOpenByIdURL">
	<portlet:param name="action" value="deleteCheckedSubjectOpenById" />
</portlet:actionURL>

<portlet:actionURL var="showPageUpdateSubjectOpenByIdURL">
	<portlet:param name="action" value="showPageUpdateSubjectOpenById" />
</portlet:actionURL>


<liferay-ui:success key="success" message="Cập nhật thành công" />
<liferay-ui:error key="fail" message="Cập nhật thất bại" />

<c:forEach items="${listSemester}" var="e">
	<h1>Năm học hiện tại: ${e.yearOfSemester}, HK${e.semester}</h1>
	<form action="${editYearOfSemesterURL}" method="post">
		<input type="hidden" value="${e.yearOfSemester}"
			name='<portlet:namespace/>yearOfSemes' /> <input type="hidden"
			value="${e.semester}" name='<portlet:namespace/>semes' /> <input
			type="hidden" name="idYear" value="${e.id}" />
		<button type="submit" class="btn-success"
			name='increaseYearOfSemester'
			onclick="return confirm('Bạn muốn tạo hk mới?')">Tăng học kì</button>
	</form>
	<form action="${decreaseSemesterByIdURL}" method="post">
		<input type="hidden" value="${e.id}"
			name='<portlet:namespace/>idDecrease' />
		<button type="submit" class="btn-warning"
			onclick="return confirm('Bạn có chắc muốn giảm hk hiện tại?')">Giảm
			học kì</button>
	</form>
</c:forEach>

<form action="${showSubjectByFacultyURL}" method="post">
	<select name='<portlet:namespace/>idFaculty'>
		<option>Khoa</option>
		<c:forEach items="${listFaculty}" var="e">
			<option value="${e.idFaculty}"
				<c:if test="${idFaculty==e.idFaculty}">selected="selected"</c:if>>${e.nameFaculty}</option>
		</c:forEach>
	</select>
	<c:forEach items="${listSemester}" var="e">
		<input type="hidden" value="${e.id}"
			name='<portlet:namespace/>idYearR' />
	</c:forEach>
	<button class="btn-success" type="submit">Chọn</button>
</form>

<c:if test="${not empty listSubject}">
	<form action="${deleteCheckedSubjectByIdURL}" method="post">
		<table class="table table-striped table-hover">
			<thead>
				<tr>
					<td>Mã môn</td>
					<td>Tên môn</td>
					<td>Số tín chỉ</td>
					<td></td>
				</tr>
			</thead>
			<tbody>
				<c:forEach items="${listSubject}" var="f">
					<tr>
						<td>${f.idSubject}</td>
						<td>${f.nameSubject}</td>
						<td>${f.numberOfCredit}</td>
					</tr>
				</c:forEach>
			</tbody>
		</table>

	</form>

	<h3>Các môn học được mở của khoa</h3>
	<form action="${showPageInsertNewSubjectURL}" method="post">
		<c:forEach items="${listSemester}" var="e">
			<input type="hidden" value="${e.id}"
				name='<portlet:namespace/>idYearS' />
			<button class="btn-success" type="submit">Tạo môn học cho HK</button>
		</c:forEach>
	</form>


	<table class="table table-striped table-hover">
		<thead>
			<tr>
				<td>Số thứ tự</td>
				<td>Tên môn</td>
				<td>Tên GV</td>
				<td>Tên phòng</td>
				<td>Tiết học</td>
				<td>Lớp</td>
				<td>Học kì</td>
				<td>Năm học</td>
				<td>Ngày bắt đầu</td>
				<td>Ngày kết thúc</td>
				<td></td>
			</tr>
		</thead>
		<c:if test="${not empty listSubjectOpen}">
			<tbody>
				<c:forEach items="${listSubjectOpen}" var="s">
					<tr>
						<td>${s.idSubjectOpen}</td>
						<td>${s.nameSubject}</td>
						<td>${s.nameTeacher}</td>
						<td>${s.nameRoom}</td>
						<td>${s.rankOfLesson}</td>
						<td>${s.nameOfClass}</td>
						<td>${s.semester}</td>
						<td>${s.yearOfSemester}</td>
						<td>${s.dateStart}</td>
						<td>${s.dateEnd}</td>
						<td>
							<form action="${showPageUpdateSubjectOpenByIdURL}" method="post">
								<input type="hidden" value="${s.idSubjectOpen}"
									name='<portlet:namespace/>idSubjectOpen' />
								<button type="submit" class="btn-info"
									onclick="return confirm('Bạn có muốn chỉnh sửa không?')">Chỉnh sửa</button>
							</form>
							<form action="${deleteCheckedSubjectOpenByIdURL}" method="post">
								<input type="hidden" value="${s.idSubjectOpen}"
									name='<portlet:namespace/>idSubjectOpen' />
								<button type="submit" class="btn-danger"
									onclick="return confirm('Bạn có muốn xoá không?')">Delete</button>
							</form>
						</td>
					</tr>
				</c:forEach>
			</tbody>
		</c:if>
		<c:if test="${empty listSubjectOpen}">
			<tbody>
				<tr>
					<td>Khoa chưa mở lớp trong năm học này</td>
				</tr>
			</tbody>
		</c:if>
	</table>

</c:if>
